﻿// 

void memcpy(char* dest, const char* src, int size);
void print_string(const char* s);
void print_char(char c);

static const char word_H[16][9] = {
	"00000000",
	"11100111",
	"01000010",
	"01000010",
	"01000010",
	"01000010",
	"01000010",
	"01111110",
	"01000010",
	"01000010",
	"01000010",
	"01000010",
	"01000010",
	"11100111",
	"00000000",
	"00000000"
};

static const char word_e[16][9] = {
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00111000",
	"01000100",
	"10000010",
	"10000010",
	"11111100",
	"10000000",
	"10000010",
	"01000010",
	"00111100",
	"00000000",
	"00000000"
};

static const char word_l[16][9] = {
	"00110000",
	"00010000",
	"00010000",
	"00010000",
	"00010000",
	"00010000",
	"00010000",
	"00010000",
	"00010000",
	"00010000",
	"00010000",
	"00010000",
	"00010000",
	"00111000",
	"00000000",
	"00000000"
};

static const char word_o[16][9] = {
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00111000",
	"01000100",
	"10000010",
	"10000010",
	"10000010",
	"10000010",
	"10000010",
	"01000100",
	"00111000",
	"00000000",
	"00000000"
};

static const char word_space[16][9] = {
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000"
};

static const char word_W[16][9] = {
	"00000000",
	"11100111",
	"01000010",
	"01000010",
	"01111110",
	"01011010",
	"01011010",
	"01011010",
	"01011010",
	"00100100",
	"00100100",
	"00100100",
	"00100100",
	"00100100",
	"00000000",
	"00000000"
};

static const char word_r[16][9] = {
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"00000000",
	"11011100",
	"01100010",
	"01000010",
	"01000000",
	"01000000",
	"01000000",
	"01000000",
	"01000000",
	"11100000",
	"00000000",
	"00000000"
};

static const char word_d[16][9] = {
	"00001100",
	"00000100",
	"00000100",
	"00000100",
	"00000100",
	"00110100",
	"01001100",
	"10000100",
	"10000100",
	"10000100",
	"10000100",
	"10000100",
	"01001100",
	"00110110",
	"00000000",
	"00000000"
};

static int iOffsetX;

static void* words[255] = {0};

int kernel_init()
{	
	memcpy((char*)0x2000, (const char*)0x1000, 1024);
	
	iOffsetX = 0;
	
	words['H'] = (void*)word_H;
	words['e'] = (void*)word_e;
	words['l'] = (void*)word_l;
	words['o'] = (void*)word_o;
	words[' '] = (void*)word_space;
	words['W'] = (void*)word_W;
	words['r'] = (void*)word_r;
	words['d'] = (void*)word_d;
	
	print_string("Hello World");

	while(true);
	
	return 0;
}

void memcpy(char* dest, const char* src, int size)
{
	while(size--)
	{
		*(dest++) = *(src++);
	}
}

void print_string(const char* s)
{
	++s; // why?
	while(*s)
	{
		print_char(*s);
		++s;
	}
}

void print_char(char c)
{
	char* video = (char*)0xA0000;
	char* word = (char*)words[(int)c];
	
	for(int i = 0; i < 16; ++i)
	{
		for(int j = 0; j < 9; ++j)
		{
			if(*(word + i * 9 + j) == '1') video[i * 320 + j + iOffsetX] = 15;
		}
	}
	iOffsetX += 8;
}